package inventory.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiParam;

/**
 * 返回数据格式定义
 */
@ApiModel(value = "统一返回对象",description = "请求结果无论成功与否,都将返回此对象，请求结果将展现在其中")
public class ResultData<T> {

    @ApiParam(name = "返回信息")
    private String resultIns;//返回信息
    @ApiParam(name = "返回状态")
    private Integer resultStatus;//返回状态
    @ApiParam(name = "返回对象集")
    private T[] objs;//返回对象集

    public ResultData(){}

    public ResultData OK(){
        this.resultIns = ResultStatus.SUCCESS.getIns();
        this.resultStatus = ResultStatus.SUCCESS.getStatus();
        return this;
    }

    public ResultData FAILD(){
        this.resultIns = ResultStatus.FAILD.getIns();
        this.resultStatus = ResultStatus.FAILD.getStatus();
        return this;
    }


    public ResultData(String resultIns, Integer resultStatus, T... objs) {
        this.resultIns = resultIns;
        this.resultStatus = resultStatus;
        this.objs = objs;
    }

    public ResultData(String resultIns, Integer resultStatus) {
        this.resultIns = resultIns;
        this.resultStatus = resultStatus;
    }

    public String getResultIns() {
        return resultIns;
    }

    public ResultData setResultIns(String resultIns) {
        this.resultIns = resultIns;
        return this;
    }

    public Integer getResultStatus() {
        return resultStatus;
    }

    private ResultData setResultStatus(Integer resultStatus) {
        this.resultStatus = resultStatus;
        return this;
    }

    public T[] getObjs() {
        return objs;
    }

    @SafeVarargs
    public final ResultData setObjs(T... objs) {
        if (objs != null){
            this.objs = objs;
        }
        return this;
    }
}
